#include<iostream>
struct Node
{
    int data;
    Node* next;
};

Node* head = nullptr;
void Insert(int data)
{
    Node* temp = new Node();
    temp->data = data;
    temp->next = nullptr;
    if (head ==nullptr)
    {
        head = temp;
        return;
    }
    Node* temp1 = head;
    while (temp1->next!=nullptr)
    {
        temp1 = temp1->next;
    }
    temp1->next = temp;
}
void Delete(int n)
{
    Node* temp1 = head;
    if(n == 1)
    {
        head = temp1->next;
        delete(head);
     }
    for (int i = 0; i < n-2; i++)
    {
        temp1 = temp1->next;
    }
    Node* temp2 = temp1->next;//th(n)
    temp1->next = temp2->next;
    delete(temp2);
}
void Print()
{
    Node* temp1 =head;
    while (temp1->next!=nullptr)
    {
        std::cout<<temp1->data<<" ";
        temp1 = temp1->next;
    }
}



int main()
{
    Insert(2);
    Insert(4);    
    Insert(6);    
    Insert(5);    
    Insert(7);
    Print();
    int n;
    std::cout<<std::endl;
    std::cin>>n;
    Delete(n);
    Print();
}
